import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.Calendar;


import javax.swing.JPanel;



public class DayInfo extends JPanel 
{
	private String nameDay; //imieniny;
	private Calendar date;
	private String sunrise;
	private String sunset;
	private Font f;
	

	DayInfo ()
	{
		super();
        date = Calendar.getInstance();
        nameDay = new String ("Beaty i Jadwigi");
  		sunrise = new String ("Wschód Słońca: 6.04");
  		sunset = new String ("Zachód Słońca: 14.04");
  		this.setPreferredSize(new Dimension(250,150));
       
        
	}
	
	public void Update (Calendar date, String nameDay)
	{
		this.date=date;
		this.nameDay = nameDay;
		repaint();
	}

	    public void paintComponent(Graphics g) {
	        super.paintComponent(g);
	        
	        Font f = new Font ("Times New Roman", Font.PLAIN, 18);
	        FontMetrics fm   = g.getFontMetrics(f);
	        Rectangle2D rect = fm.getStringBounds(nameDay, g);
	        g.setFont(f);
			g.drawString(nameDay,(int)(getWidth()/2-rect.getWidth()/2), 20);
			
			f = new Font ("Times New Roman", Font.PLAIN, 72);
	        fm   = g.getFontMetrics(f);
	        rect = fm.getStringBounds(String.valueOf(date.get(Calendar.DATE)), g);
	        g.setFont(f);
			g.drawString(String.valueOf(date.get(Calendar.DATE)),(int)(getWidth()/2-rect.getWidth()/2), 80);
			
			f = new Font ("Times New Roman", Font.PLAIN, 26);
	        fm   = g.getFontMetrics(f);
	        rect = fm.getStringBounds(monthPl(date.get(Calendar.MONTH)), g);
	        g.setFont(f);
			g.drawString(monthPl(date.get(Calendar.MONTH)),(int)(getWidth()/2-rect.getWidth()/2), 105);
			
			f = new Font ("Times New Roman", Font.PLAIN, 12);
			g.setFont(f);
			g.drawString(sunrise,10,130);
			g.drawString(sunset,140,130);
			
	    }
	    private String monthPl(int m)
	    {
	    	String month = new String();
	    	switch (m)
	    	{
	    	case Calendar.JANUARY: month = "STYCZEŃ"; break;
	    	case Calendar.FEBRUARY: month = "LUTY"; break;
	    	case Calendar.MARCH: month = "MARZEC"; break;
	    	case Calendar.APRIL: month = "KWIECIEŃ"; break;
	    	case Calendar.MAY: month= "MAJ"; break;
	    	case Calendar.JUNE: month = "CZERWIEC"; break;
	    	case Calendar.JULY: month = "LIPIEC"; break;
	    	case Calendar.AUGUST: month = "SIERPIEŃ"; break;
	    	case Calendar.SEPTEMBER: month = "WRZESIEŃ"; break;
	    	case Calendar.OCTOBER: month = "PAŹDZIERNIK"; break;
	    	case Calendar.NOVEMBER: month = "LISTOPAD"; break;
	    	case Calendar.DECEMBER: month = "GRUDZIEŃ"; break;
	    	}
	    	return month;
	    }
}

